const version = {};

version.getVersion = function () {
  let result = {};
  const versionThread = threads.start(function () {
    const res = http.get(
      app.versionName == "4.1.1 Alpha2"
        ? "http://xxxx:8000/api/getEdition/"// 本地api
        : "http://xxxx/api/getEdition/"// 远程服务端api
    );

    if (res.statusCode != 200) {
      toast("请求失败: " + res.statusCode + " " + res.statusMessage);
      result = {
        state: false,
      };
    } else {
      const contents = JSON.parse(res.body.string());
      if (contents.success) {
        result = {
          state: true,
          version: JSON.parse(contents.data).versionName,
        };
        console.log(JSON.parse(contents.data).versionName);
      } else {
        result = {
          state: false,
        };
      }
    }
  });
  versionThread.join();
  return result;
};

module.exports = version;
